package com.yjt.javatest.controller;

import com.yjt.javatest.service.StudentService;
import com.yjt.javatest.utils.APIResponse;
import com.yjt.javatest.utils.ErrorCode;
import com.yjt.javatest.entity.vo.AnswerVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/student")
@PreAuthorize("@ex.isStudent()")
@Tag(name = "学生操作")
public class StudentController {
    @Autowired
    StudentService studentService;

    @PostMapping("/submitAnswer")
    @Operation(summary = "提交答案")
    public APIResponse submitAnswer(@RequestBody AnswerVo answerVo){
        try{
            return studentService.submitAnswer(answerVo);
        }catch (Exception e){
            e.printStackTrace();
            return APIResponse.error(ErrorCode.SERVER_ERROR.getCode(),"[Controller][submitAnswer]");
        }
    }

    @GetMapping("/testInfo")
    @Operation(summary = "获取所有参与的测试信息", description = "测试信息包括testId,测试标题和得分,未公布的测试得分为-1")
    public APIResponse getTestInfo() {
        return studentService.getTestInfo();
    }
}
